//
//  UIBarButtonItem+Extension.swift
//  weiboCopycat
//
//  Created by Orange Yu on 2016/11/30.
//  Copyright © 2016年 Orange Yu. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    convenience init(title: String,imageName: String? = nil,target: Any?,action: Selector) {
        self.init()
        
        let button = UIButton()
        button.setTitle(title, for: .normal)
        button.setTitleColor(UIColor.darkGray, for: .normal)
        button.setTitleColor(UIColor.orange, for: .highlighted)
        
        if imageName != nil {
            button.setImage(UIImage(named:imageName!), for: .normal)
        }
        
        button.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        button.sizeToFit()
        
        
        button.addTarget(target, action: action, for: .touchUpInside)
        self.customView = button
        
        
    }
}
